//导入express模块
const express = require('express')
//导入logo模块
const favicon = require('serve-favicon')
//导入路径模块
const path = require('path')
//导入自定义user模块
const { router: user } = require('./routes/user')
//导入session模块
const session = require('express-session')
//创建express服务
const app = express()
//配置ejs模板引擎
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
//配置session
app.use(session({
        secret: 'zidingyidenasha',
        resave: false,
        saveUninitialized: true
    }))
//配置网页logo路径
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
//配置静态资源路径
app.use(express.static('public'))
//配置post请求
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
//将uesr路径传递给对应路由处理
app.use('/user', user)
//错误处理中间件
app.use((req, res, next) => {
    res.status(404)
    res.send('页面找不到了')
})
//监听端口
app.listen(3000, err => {
    console.log('服务器已经在3000端口启动');
})
